#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#define inf 0x3f3f3f3f
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<int, int> PII;
const int N = 1e4 + 10;
int n, m;
int op;
int fa[N], d[N];
unordered_map<int, int> ma;

int find(int x)
{
    if (fa[x] != x)
    {
        int tmp = find(fa[x]);
        d[x] += d[fa[x]];
        fa[x] = tmp;
    }
    return fa[x];
}

int get(int x)
{
    if (ma.count(x) == 0)
        ma[x] = op++;
    return ma[x];
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= N; i++)
        fa[i] = i;
    int res = m;
    for (int i = 1; i <= m; i++)
    {
        int a, b;
        string s;
        cin >> a >> b >> s;
        a = get(a - 1);
        b = get(b);
        int t = 0;
        if (s == "odd")
            t = 1;
        int pa = find(a), pb = find(b);
        if (pa == pb)
        {
            if (((d[b] - d[a]) % 2 + 2) % 2 != t)
            {
                res = i - 1;
                break;
            }
        }
        else
        {
            fa[pa] = pb;
            d[pa] = (d[b] - d[a] + t) % 2;
        }
    }
    cout << res;
    return 0;
}